package com.cy.stone.system.adapter;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.cy.stone.common.base.AddGroup;
import com.cy.stone.common.base.EditGroup;
import com.cy.stone.framework.log.annotation.Log;
import com.cy.stone.framework.log.enums.BusinessType;
import com.cy.stone.system.application.RoleApi;
import com.cy.stone.system.application.RoleMenuApi;
import com.cy.stone.system.domain.clientobject.role.RoleCO;
import com.cy.stone.system.domain.clientobject.role.RoleMenuCO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色相关接口
 * @author Wings
 * @since 2023-12-10
 */
@RestController
@RequestMapping("/role/")
@RequiredArgsConstructor
@SaCheckLogin
@Tag(name = "角色服务适配器")
public class RoleController {

    private final RoleApi roleApi;

    private final RoleMenuApi roleMenuApi;

    @PostMapping("addRole")
    @Operation(summary = "新增角色")
    @Log(title = "新增角色", businessType = BusinessType.INSERT, isSaveResponseData = false)
    public void addRole(@RequestBody @Validated(AddGroup.class) RoleCO roleCO) {
        roleApi.addRole(roleCO);
    }

    @PostMapping("editRole")
    @Operation(summary = "编辑角色")
    @Log(title = "编辑角色", businessType = BusinessType.UPDATE, isSaveResponseData = false)
    public void editRole(@RequestBody @Validated(EditGroup.class) RoleCO roleCO) {
        roleApi.editRole(roleCO);
    }

    @PostMapping("menuRelate")
    @Operation(summary = "关联菜单资源")
    @Log(title = "关联菜单资源", businessType = BusinessType.UPDATE, isSaveResponseData = false)
    public void menuRelate(@RequestBody @Validated RoleMenuCO roleMenuCO) {
        roleMenuApi.menuRelate(roleMenuCO);
    }
}
